package com.raos.example.chat;

import dev.langchain4j.community.model.zhipu.ZhipuAiStreamingChatModel;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

/**
 * 流式会话大模型配置类
 *
 * @author raos
 * @date 2025-07-08
 */
@Configuration
public class StreamingChatConfig {

    @Value("${langchain4j.deepseek.streaming-chat-model.base-url}")
    private String deepseekBaseUrl;
    @Value("${langchain4j.deepseek.streaming-chat-model.api-key}")
    private String deepseekApiKey;
    @Value("${langchain4j.deepseek.streaming-chat-model.model-name}")
    private String deepseekModelName;

    @Bean("deepseekStreamingChatModel")
    public OpenAiStreamingChatModel streamingChatModel() {
        return OpenAiStreamingChatModel.builder()
                .baseUrl(deepseekBaseUrl)
                .apiKey(deepseekApiKey)
                .modelName(deepseekModelName)
                .build();
    }

    @Bean("zhipuAiStreamingChatModel")
    public ZhipuAiStreamingChatModel zhipuAiStreamingChatModel(
            @Value("${langchain4j.community.zhipu.streaming-chat-model.api-key}") String zhipuApiKey,
            @Value("${langchain4j.community.zhipu.streaming-chat-model.model-name}") String zhipuModelName) {
        return ZhipuAiStreamingChatModel.builder()
                .apiKey(zhipuApiKey)
                .model(zhipuModelName)
                .callTimeout(Duration.ZERO)
                .connectTimeout(Duration.ZERO)
                .writeTimeout(Duration.ZERO)
                .readTimeout(Duration.ZERO)
                .build();
    }

}
